/**
 * 测试数据文件
 * 包含不同类型的testDetail JSON数据示例
 */

// OP23Data - 螺丝拧紧类型测试数据（完整版，展示分组效果）
export const screwTestData = {
  // 基础信息（无后缀）
  screwCCDResult: 1,
  screwBtachNo: [83, 67, 82, 69, 87, 45, 50, 48, 50, 52, 48, 49, 48, 49, 0, 0],
  adapterBoardMaterialNo: [65, 68, 65, 80, 84, 69, 82, 45, 49, 50, 51, 52, 0, 0],

  // 第1组 - 1#螺丝相关参数
  tightenResult01: 1,
  programNo01: 101,
  minTorque01: 2.5,
  actTorque01: 3.2,
  maxTorque01: 4.0,
  minAngle01: 45.0,
  actAngle01: 52.3,
  maxAngle01: 60.0,

  // 第2组 - 2#螺丝相关参数
  tightenResult02: 1,
  programNo02: 102,
  minTorque02: 2.8,
  actTorque02: 3.5,
  maxTorque02: 4.2,
  minAngle02: 48.0,
  actAngle02: 55.1,
  maxAngle02: 62.0,

  // 第3组 - 3#螺丝相关参数
  tightenResult03: 0,
  programNo03: 103,
  minTorque03: 2.6,
  actTorque03: 3.1,
  maxTorque03: 3.8,
  minAngle03: 46.0,
  actAngle03: 51.8,
  maxAngle03: 58.0,

  // 第4组 - 4#螺丝相关参数
  tightenResult04: 1,
  programNo04: 104,
  minTorque04: 2.7,
  actTorque04: 3.3,
  maxTorque04: 4.1,
  minAngle04: 47.0,
  actAngle04: 53.2,
  maxAngle04: 61.0
}

// OP25_1Data - 电阻测试类型测试数据
export const resistanceTestData = {
  testResistanceResult01: 1,
  testResistanceResult02: 1,
  testResistanceResult03: 0,
  testDielectricResult: 1,
  testHeightVoltageResult: 1,
  testProgramNo: 201,
  testResistance01: 0.025,
  testResistanceMax01: 0.100,
  testResistanceMin01: 0.001,
  testResistance02: 0.032,
  testResistanceMax02: 0.100,
  testResistanceMin02: 0.001,
  testResistance03: 0.028,
  testResistanceMax03: 0.100,
  testResistanceMin03: 0.001,
  testDielectric: 15.6,
  testDielectricMax: 20.0,
  testDielectricMin: 10.0,
  testHeightVoltage: 0.5,
  testHeightVoltageMax: 1.0,
  testHeightVoltageMin: 0.0
}

// OP02_1DataFirst - 上料类型测试数据
export const loadTestData = {
  partLoadResult: 1,
  housingMaterialNo: [72, 79, 85, 83, 73, 78, 71, 45, 49, 50, 51, 52, 53, 54, 0, 0],
  controllerMaterialNo: [67, 79, 78, 84, 82, 79, 76, 45, 54, 55, 56, 57, 48, 49, 0, 0],
  phaseMaterialNo: [80, 72, 65, 83, 69, 45, 65, 66, 67, 68, 69, 70, 0, 0],
  wireMaterialNo: [87, 73, 82, 69, 45, 49, 50, 51, 52, 53, 54, 55, 0, 0],
  busbarMaterialNo: [66, 85, 83, 66, 65, 82, 45, 88, 89, 90, 49, 50, 51, 0, 0]
}

// OP03Data - 涂胶类型测试数据
export const glueTestData = {
  glueHousingResult: 1,
  glueControllerResult: 1,
  gluePhaseResult: 0,
  glueWireResult: 1,
  glueBusbarResult: 1,
  glueBatchNo: [71, 76, 85, 69, 45, 50, 48, 50, 52, 48, 49, 48, 49, 0, 0]
}

// OP02_2Data - 清洗类型测试数据
export const cleanTestData = {
  housingPlasmaResult: 1,
  controllerPlasmaResult: 1,
  phasePlasmaResult: 0,
  wirePlasmaResult: 1,
  busbarPlasmaResult: 1
}

// OP27DataFirst - 相机检测类型测试数据
export const cameraTestData = {
  partCCDResult1: 1,
  cameraResult01: 1,
  cameraResult02: 0,
  cameraResult03: 1,
  oringCCDResult: 1
}

// 混合类型测试数据（包含多种类型的字段）
export const mixedTestData = {
  screwCCDResult: 1,
  tightenResult01: 1,
  partLoadResult: 1,
  glueHousingResult: 0,
  testResistanceResult01: 1
}

// 空数据测试
export const emptyTestData = {}

// 无效数据测试
export const invalidTestData = {
  unknownField1: 'test',
  unknownField2: 123,
  unknownField3: true
}

// 所有测试数据的映射
export const testDataMap = {
  screw: {
    name: '螺丝拧紧类型 (OP23Data)',
    data: screwTestData
  },
  resistance: {
    name: '电阻测试类型 (OP25_1Data)',
    data: resistanceTestData
  },
  load: {
    name: '上料类型 (OP02_1DataFirst)',
    data: loadTestData
  },
  glue: {
    name: '涂胶类型 (OP03Data)',
    data: glueTestData
  },
  clean: {
    name: '清洗类型 (OP02_2Data)',
    data: cleanTestData
  },
  camera: {
    name: '相机检测类型 (OP27DataFirst)',
    data: cameraTestData
  },
  mixed: {
    name: '混合类型',
    data: mixedTestData
  },
  empty: {
    name: '空数据',
    data: emptyTestData
  },
  invalid: {
    name: '无效数据',
    data: invalidTestData
  }
}

/**
 * 获取测试数据
 * @param {string} type 数据类型
 * @returns {object} 测试数据
 */
export function getTestData(type) {
  return testDataMap[type]?.data || {}
}

/**
 * 获取所有测试数据类型
 * @returns {array} 测试数据类型列表
 */
export function getTestDataTypes() {
  return Object.keys(testDataMap).map(key => ({
    key,
    name: testDataMap[key].name
  }))
}

/**
 * 生成随机测试数据
 * @param {string} type 数据类型
 * @returns {object} 随机测试数据
 */
export function generateRandomTestData(type) {
  const baseData = getTestData(type)
  const randomData = { ...baseData }

  // 随机修改一些数值
  Object.keys(randomData).forEach(key => {
    const value = randomData[key]
    if (typeof value === 'number' && key.includes('Result')) {
      // 结果字段随机设置为0或1
      randomData[key] = Math.random() > 0.5 ? 1 : 0
    } else if (typeof value === 'number' && !Number.isInteger(value)) {
      // 浮点数字段添加随机变化
      randomData[key] = value + (Math.random() - 0.5) * 0.1
    }
  })

  return randomData
}

/**
 * 将测试数据转换为JSON字符串
 * @param {string} type 数据类型
 * @returns {string} JSON字符串
 */
export function getTestDataAsJson(type) {
  return JSON.stringify(getTestData(type), null, 2)
}
